package com.itheima.edu.info.manger.service;

import com.itheima.edu.info.manger.dao.StudentDao;
import com.itheima.edu.info.manger.dao.TeacherDao;
import com.itheima.edu.info.manger.domain.Student;
import com.itheima.edu.info.manger.domain.Teacher;

public class TeacherService {
    TeacherDao teacherDao=new TeacherDao();
    public boolean addteacher(Teacher teacher) {
         return teacherDao.addteacher(teacher);
    }

    public boolean isExcies(String tid) {
        Teacher[] teachers=teacherDao.findteacherid();
        boolean exist=false;
        for (int i = 0; i < teachers.length; i++) {
            Teacher teach= teachers[i];
            if(teach !=null && teach.getId().equals(tid)){
                exist=true;
                break;
            }
        }
        return exist;
    }


    public void deleteid(String detid) {
        teacherDao.deleteid(detid);
    }

    public void updatateacher(String uptid, Teacher newstu) {
        teacherDao.updatasteacher(uptid,newstu);
    }

    public Teacher[] findteacher() {
        //调用dao层findstudent方法
        Teacher[] allteacher=teacherDao.findteacher();
        //判断是否有学生数据（有返回地址,没有为null
        boolean flog=false;
        for (int i = 0; i < allteacher.length; i++) {
            Teacher teacher=allteacher[i];
            if(teacher !=null){
                flog=true;
                break;
            }
        }
        if(flog){
            return allteacher;
        }else {
            return null;
        }
    }
}
